package m3_publishsubscribe;

import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.ConnectionFactory;

import java.util.Scanner;

public class Producter {
    public static void main(String[] args) throws Exception {
        ConnectionFactory f = new ConnectionFactory();
        f.setHost("192.168.126.129");
        f.setUsername("admin");
        f.setPassword("admin");
        //定义交换机
        Channel channel = f.newConnection().createChannel();
        channel.exchangeDeclare("logs", BuiltinExchangeType.FANOUT);
        //向交换机发消息
        while (true){
            System.out.print("输入消息:");
            String msg = new Scanner(System.in).nextLine();

            channel.basicPublish("logs","",null,msg.getBytes());
        }

    }
}
